package com.xxx.service.db.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxx.domain.db.User;
import com.xxx.mapper.UserMapper;
import com.xxx.service.db.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@DubboService // 暴露服务
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public Long save(User user) {

        // 完善用户数据
        user.setPassword(SecureUtil.md5(user.getHxPassword())); // md5加密
        user.setCreated(new Date());
        user.setUpdated(new Date());

        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findByMobile(String mobile) {

        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile",mobile);

        return userMapper.selectOne(qw);
    }
}
